package dreamdancetiktokfuncs

import (
	"strings"
	"time"
)

func GetCpRankKey(category int32) string {
	nowTime := time.Now()
	//获取当前时间,动态匹配key
	firstDay := GetFirstDateOfWeek(nowTime)
	LastLastFiveDay := firstDay.AddDate(0, 0, -10).Format(time.DateOnly) //上上周5
	LastFourDay := firstDay.AddDate(0, 0, -4).Format(time.DateOnly)      //上周4
	LastFiveDay := firstDay.AddDate(0, 0, -3).Format(time.DateOnly)      //上周5
	thisFourDay := firstDay.AddDate(0, 0, 3).Format(time.DateOnly)       // 这周4
	thisFiveDay := firstDay.AddDate(0, 0, 4).Format(time.DateOnly)       // 这周五
	nextFourDay := firstDay.AddDate(0, 0, 10).Format(time.DateOnly)      // 下周四
	specialNumber := nowTime.Weekday()
	//如果当前是大于等于周五，算到下一轮，否则上一轮
	zSetKey := LastFiveDay + "间" + thisFourDay
	if specialNumber >= 5 || specialNumber == 0 {
		zSetKey = thisFiveDay + "间" + nextFourDay
	}
	if category != 0 {
		if specialNumber >= 5 || specialNumber == 0 {
			zSetKey = LastFiveDay + "间" + thisFourDay
		} else {
			zSetKey = LastLastFiveDay + "间" + LastFourDay
		}
	}
	return zSetKey
}

func CompareUserIds(userId, userIdOther, splicing string) string {
	if splicing == "" {
		splicing = "和"

	}
	userIdsKey := userId + splicing + userIdOther
	if compare := strings.Compare(userId, userIdOther); compare == -1 {
	} else {
		userIdsKey = userIdOther + splicing + userId
	}
	return userIdsKey
}

func GetFirstDateOfWeek(now time.Time) (weekMonday time.Time) {
	offset := int(time.Monday - now.Weekday())
	if offset > 0 {
		offset = -6
	}
	weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
	return weekStartDate
}

func GetZeroTimeStamp(now time.Time) int64 {
	zeroTime := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
	return zeroTime.Unix()
}
